import React, { Component } from 'react'
import './index.scss'
const BMapGL = window.BMap
// const icon = 'http://www.jisuxia.com/uploadfile/2019/0902/20190902044023702.gif'
const icon = 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1572869787163&di=3f12c557c15d90cc9a7e40401703837b&imgtype=0&src=http%3A%2F%2Fimgsrc.baidu.com%2Fforum%2Fw%3D580%2Fsign%3D5bfde59e4a90f60304b09c4f0913b370%2Fc0d8f358ccbf6c8151754547bc3eb13532fa40bd.jpg'


export default class index extends Component {
  componentDidMount() {
    // 初始化百度地图 
    var map = new window.BMap.Map("container");
    // console.log(map)
    // 设置经纬度 
    // var point = new window.BMapGL.Point(116.404, 39.915);
    // // 渲染设置中心点和缩放的级别
    // map.centerAndZoom(point, 15);

    // 创建地址解析器实例
    var myGeo = new BMapGL.Geocoder();
    // console.log(myGeo)
    // 将地址解析结果显示在地图上,并调整地图视野
    myGeo.getPoint("麓谷企业广场A2栋", function (point) {
      if (point) {
        map.centerAndZoom(point, 18);
        // map.addOverlay(new BMapGL.Marker(point));

        // var walking = new BMapGL.WalkingRoute(map, { renderOptions: { map: map, autoViewport: true } });
        // walking.search("豪天宾馆", "麓谷企业广场A2栋");

        var myIcon = new BMapGL.Icon(icon, new BMapGL.Size(150, 157));
        var marker2 = new BMapGL.Marker(point, { icon: myIcon });  // 创建标注
        map.addOverlay(marker2);
      } else {
        alert("您选择地址没有解析到结果!");
      }
    }, "长沙市");
  }
  render() {
    return (
      <div className="home">
        <div id="container"></div>
      </div>
    )
  }
}
